﻿/****************************************************************************** 
 * 文件名称: UIMessageBox.cs
 * 文件说明: 消息提示窗体
 * 当前版本: V3.0
 * 创建日期: 2020-01-01
 *
 * 2020-01-01: V2.2.0 增加文件说明
******************************************************************************/

using System;
using System.Drawing;
using System.Windows.Forms;

namespace Bojay.UI
{
    public sealed partial class UIMessageForm : UIForm
    {
        public UIMessageForm()
        {
            InitializeComponent();

            btnOK.Text = UILocalize.OK;
            btnCancel.Text = UILocalize.Cancel;

        }

        public bool IsOK
        {
            get; private set;
        }

        private bool _showCancel = true;

        public bool ShowCancel
        {
            get => _showCancel;
            set
            {
                _showCancel = value;
                btnCancel.Visible = value;
                OnSizeChanged(null);
            }
        }

        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);

            if (btnOK == null || btnCancel == null)
            {
                return;
            }

            if (_showCancel)
            {
                btnOK.Location = new Point(485, 260);
                btnCancel.Location = new Point(600, 260);
            }
            else
            {
                btnOK.Location = new Point(600, 260);
            }

            //btnCancel.Left = btnOK.Right - 1;
        }

        protected override void DoEnter()
        {
            base.DoEnter();
            btnOK_Click(null, null);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            IsOK = true;
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            IsOK = false;
            Close();
        }

        public override void SetStyleColor(UIBaseStyle uiColor)
        {
            base.SetStyleColor(uiColor);
            if (btnOK != null)
            {
                //btnOK.FillColor = BackColor;
                //btnOK.RectColor = Color.FromArgb(36, uiColor.RectColor);
                //btnOK.ForeColor = uiColor.LabelForeColor;

                //btnOK.RectSides = ToolStripStatusLabelBorderSides.None;
                //btnOK.RectColor = Color.White;
                //btnOK.ForeColor = Color.White;
            }

            if (btnCancel != null)
            {
                //btnCancel.FillColor = BackColor;
                //btnCancel.RectColor = Color.FromArgb(36, uiColor.RectColor);
                //btnCancel.ForeColor = uiColor.LabelForeColor;

                //btnCancel.RectSides = ToolStripStatusLabelBorderSides.None;
                //btnCancel.RectColor = Color.White;
                //btnCancel.ForeColor = Color.White;
            }

            if (lbMsg != null)
            {
                //lbMsg.ForeColor = uiColor.LabelForeColor;
                //lbMsg.BackColor = BackColor;
                //lbMsg.SelectionColor = RectColor;
            }
        }

        private void btnOK_MouseEnter(object sender, EventArgs e)
        {
            ((UIButton)sender).RadiusSides = UICornerRadiusSides.All;
        }

        private void btnOK_MouseLeave(object sender, EventArgs e)
        {
            ((UIButton)sender).RadiusSides = UICornerRadiusSides.None;
        }

        public void ShowMessage(string message, string title, bool showCancel, UIStyle style = UIStyle.Office2019Blue)
        {
            Style = style;
            Text = title;
            lbMsg.Text = message; 
            ShowCancel = showCancel;
        }
    }
}